package cn.tworice.client.service.impl;

import cn.tworice.client.dao.ExamDao;
import cn.tworice.client.service.ExamService;
import cn.tworice.common.entity.Exam;
import cn.tworice.common.entity.Paper;
import cn.tworice.common.entity.dto.ExamDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class ExamServiceImpl implements ExamService {
    @Autowired
    private ExamDao examDao;

    @Override
    public List<ExamDto> getExamList(Integer page, Integer pageSize) {
        return examDao.queryExamList(page * pageSize, pageSize);
    }

    @Override
    public Integer getExamTotal() {
        return examDao.queryExamTotal();
    }

    @Override
    public void setExam(Exam exam) {
        if (exam.getId() == null || exam.getId().isEmpty()) {
            exam.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            examDao.insertExam(exam);
        }else {
            examDao.updateExam(exam);
        }
    }

    @Override
    public void delExamByIds(String[] id) {
        examDao.delExamByIds(id);
    }

    /**
     * 交卷
     * @Author 二饭
     * @Email 1786705138@qq.com
     * @Date 2021/12/25 21:07
     */
    @Override
    public void setPaper(List<Paper> list) {
        examDao.delPapers(list.get(0).getAdminId(),list.get(0).getExamId());
        for(Paper paper:list){
            paper.setId(UUID.randomUUID().toString().replaceAll("-",""));
        }
        examDao.insertPaper(list,System.currentTimeMillis());
    }
}
